package com.hzhr.iot.user.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.user.controller.base.BaseController;
import com.hzhr.iot.user.model.user_registInfo.User_RegistInfoGetModel;
import com.hzhr.iot.user.model.user_registInfo.User_RegistInfoPostModel;
import com.hzhr.iot.user.service.User_RegistInfoService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "User_RegistInfo", description = "用户的注册信息")
@RestController
@RequestMapping(value = "")
public class User_RegistInfoController extends BaseController {
    @Autowired
    User_RegistInfoService user_registInfoService;

    //region /users/{userId}/regist-infos POST
    //region swagger响应码 : post
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 判断手机号的唯一性  \n----异常说明 : 手机号已注册  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : post
    @ApiOperation(value="新用户注册", notes="新用户注册  \n简介 : 创建用户；登录  \n步骤 :  \n1. 验证用户名 : (√)  \n 查询“userName = body.phone的用户(USER)”是否存在，如果存在，抛出异常201；(√)  \n2. 创建用户 : (√)  \n 根据body创建用户user_1，同时设置以下属性：  \n (1) user_1.phone = body.phone；  \n (2) user_1.companyId = 0；  \n (3) user_1.deptId = 0；  \n (4) user_1.isNewUser = 否；  \n (5) user_1.userCode = '0'；  \n (6) user_1.resourceCode = '0'；  \n3. 提交以上事务  \n4. 登录 : (√)  \n 使用user_1.userName和user_1.password调用登录服务(login-service: /tokens GET)进行登录；  \n5. 返回信息 : (√)  \n 根据条件参数查询更新结果，组装响应并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : post
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            
            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })

    //endregion
    //region 请求 : post
    @RequestMapping(value = "/users/regist-infos", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<User_RegistInfoGetModel> post(@RequestParam @ApiIgnore Map<String, Object> query,
                                                        @RequestBody User_RegistInfoPostModel body) throws ServiceException {
        User_RegistInfoGetModel responseBody = user_registInfoService.post(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion

    //region /v1/users/{userId}/regist-infos POST
    //region swagger响应码 : post1
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : post1
    @ApiOperation(value="新用户注册", notes="新用户注册  \n简介 : 创建用户；登录  \n步骤 :  \n1. 验证用户名 : (√)  \n查询“userName = body.phone的用户(USER)”是否存在，如果存在，抛出异常201；(√)  \n2. 创建用户 : (√)  \n 根据body创建用户user_1，同时设置以下属性：  \n(1) user_1.phone = body.phone；  \n(2) user_1.companyId = 0；  \n(3) user_1.deptId = 0；  \n(4) user_1.isNewUser = 否；  \n(5) user_1.userCode = '0'；  \n(6) user_1.resourceCode = '0'；  \n(7) user_1.type = '3'；  \n3. 分配权限 : (√)  \n为用户分配id=6的角色  \n4. 提交以上事务  \n5. 登录 : (√)  \n使用user_1.userName和user_1.password调用登录服务(login-service: /tokens GET)进行登录；  \n6. 返回信息 : (√)  \n根据条件参数查询更新结果，组装响应并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : post1
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })

    //endregion
    //region 请求 : post1
    @RequestMapping(value = "/v1/users/regist-infos", method = RequestMethod.POST)
    //endregion
    @Author
    public ResponseEntity<User_RegistInfoGetModel> post1(@RequestParam @ApiIgnore Map<String, Object> query,
                                                        @RequestBody User_RegistInfoPostModel body) throws ServiceException {
        User_RegistInfoGetModel responseBody = user_registInfoService.post1(initHeader(), query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
}
















































































































































































































































































































































































